home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol194 / kermasm.arc / MSTERM.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-11-14  |  13.9 KB  |  532 lines

  1. ; Edit history:
  2. ;
  3. ; [v2.28]
  4. ; Added set mode line {on/off} (From Edgar Butt, U. of Md.)
  5. ; Added clear key def routine
  6. ; JD 1 May 1985
  7.  
  8.     Public    clscpt, defkey, cptfcb, inicpt, clscpi, telnet
  9.     public  dopar, shokey, prkey, clrdef
  10.     include msdefs.h
  11.  
  12. datas     segment    public 'datas'
  13.     extrn    flags:byte, trans:byte, buff:byte, portval:word
  14.  
  15. targ    termarg    <0,1,80,24,cptchr,2dch,0,scntab,deftab,0,,parnon>
  16. ssp    dw    0        ; Save SP in Telnet.
  17. crlf    db      cr,lf,'$'
  18. tmp    db    ?,'$'
  19. temp    dw    0
  20. temp1   dw      ?               ; Temporary storage.
  21. temp2   dw      ?               ; Temporary storage.
  22. tmsg1    db    cr,lf,'[Connecting to host, type $' 
  23. tmsg3    db    ' C to return to PC]',cr,lf,cr,lf,cr,lf,'$'
  24. tmsg2    db    cr,lf,'[Back at micro]',cr,lf,'$'
  25. erms22    db    cr,lf,'?No capture file open$' ;[jd]
  26. erms2    db    cr,lf,'?No room in definition buffer, definition ignored'
  27.     db    cr,lf,'$'
  28. erms3    db    cr,lf,'?No room in scan table, definition ignored',cr,lf,'$'
  29. esctl    db    'Control-$'         ; [6]
  30.  
  31. inthlp  db    cr,lf,' ?  This message'
  32.     db    cr,lf,' C  Close the connection'
  33.     db    cr,lf,' S  Status of the connection'
  34.     db    cr,lf,' B  Send a break'
  35.     db    cr,lf,' M  Toggle mode line'
  36.     db    cr,lf,' Q  Quit logging'
  37.     db    cr,lf,' R  Resume logging'
  38.     db    cr,lf,' 0  Send a null'
  39.     db    cr,lf,' P  Push to a new command parser'
  40.     db    cr,lf,' Typing the escape character will send it to the host'
  41.     db    0
  42.  
  43. intprm    db    'Command>$'
  44.  
  45. CPTFCB    DB    25H DUP (?)
  46. CAPBUF    DB    200 DUP (?)
  47. CAPBP    DW    ?
  48. CAPLFT    DB    ?
  49.  
  50. SCNTLEN    EQU    200        ; MAX # OF DEFINITIONS ONE can have
  51. defbsiz    equ    400        ; combined length of all definitions...
  52. scntab    dw    scntlen dup (?)    ; scan codes redefined
  53. deftab    dw    scntlen dup (?) ; pointer to definition strings
  54. defbuf    db    defbsiz dup (?)
  55. defptr    dw    defbuf        ; pointer starts at beginning
  56. deflen    dw    defbsiz        ; amt of space left in buffer
  57. sttmsg    db    'Type space to continue$'
  58. shkmsg    db    cr,lf,'Press key: $'
  59. ocbuf    db    4 dup (?)
  60. datas    ends
  61.  
  62. code    segment    public
  63.     extrn     comnd:near, outchr:near, stat0:near
  64.     extrn    escprt:near, clrbuf:near, term:near
  65.     extrn    cmblnk:near, locate:near, prtchr:near
  66.     extrn    beep:near, puthlp:near
  67.     extrn    serini:near,serrst:near, sendbr:near, showkey:near
  68.     extrn    fpush:near
  69.     assume    cs:code, ds:datas
  70.  
  71. ; the show key command.
  72.  
  73. shokey    proc    near
  74.     mov    ah,cmcfm        ; confirm with carriage return
  75.     call    comnd
  76.      jmp    r            ; uh oh...
  77.     mov    dx,offset shkmsg
  78.     mov    ah,prstr
  79.     int    dos            ; print a prompt for it
  80.     mov    ax,offset targ        ; give it terminal arg block.
  81.     call    showkey            ; show them the key definition
  82.     push    ax
  83.     push    cx            ; save results
  84.     mov    dx,offset crlf
  85.     mov    ah,prstr
  86.     int    dos
  87.     pop    cx
  88.     pop    ax
  89.     call    prkey            ; print the buffer
  90.     mov    dx,offset crlf
  91.     mov    ah,prstr
  92.     int    dos
  93.     jmp    rskp            ; and return
  94. shokey    endp
  95.  
  96. ; pass a string pointer in ax, length in cx.
  97. ; Prints the string, quoting any unprintables, except crlf.
  98.  
  99. prkey    proc    near
  100.     mov    si,ax            ; copy string ptr
  101.     jcxz    prke6            ; no string, stop here
  102. prke1:    push    cx            ; save counter
  103.     lodsb                ; get a byte
  104.     and    al,7fH            ; only consider low-order 7 bits.
  105.     cmp    al,' '            ; printable?
  106.     jb    prke2            ; no, print the hard way
  107.     cmp    al,7fH            ; maybe a delete?
  108.     jne    prke4            ; no, can just put into string
  109. prke2:    jcxz    prke3            ; last char, can't be crlf
  110.     cmp    al,cr            ; carriage return?
  111.     jne    prke3            ; no, go on
  112.     cmp    byte ptr [si],lf    ; followed by linefeed?
  113.     jne    prke3
  114.     mov    ah,prstr
  115.     mov    dx,offset crlf
  116.     int    dos            ; else just print crlf
  117.     inc    si            ; skip over lf
  118.     pop    cx            ; careful...
  119.     dec    cx
  120.     push    cx
  121.     jmp    short prke5
  122. prke3:    push    ax            ; preserve the char
  123.     mov    ah,conout
  124.     mov    dl,'\'
  125.     int    dos            ; print the quote character
  126.     pop    ax
  127.     call    proct            ; print the octal byte
  128.     jmp    short prke5
  129. prke4:    mov    dl,al            ; normal char, just print it
  130.     mov    ah,conout
  131.     int    dos
  132. prke5:    pop    cx            ; restore count
  133.     loop    prke1
  134. prke6:    ret                ; and return
  135. prkey    endp
  136.  
  137. ; print the byte in al as an octal number
  138. proct    proc    near
  139.     push    si
  140.     push    di
  141.     pushf                ; save flags...
  142.     mov    ch,3            ; # of digits to print
  143.     mov    cl,3            ; shift count
  144.     mov    di,offset ocbuf+2    ; point to end of buffer
  145.     std                ; set direction to backwards
  146.     mov    dl,al            ; copy the byte
  147. proc1:    mov    al,dl
  148.     and    al,7            ; keep low-order byte
  149.     add    al,'0'            ; make printable
  150.     stosb                ; drop it off
  151.     shr    dl,cl            ; shift this digit out
  152.     dec    ch
  153.     jnz    proc1            ; loop thru all
  154.     mov    cx,3
  155.     cld                ; forward again
  156.     mov    si,offset ocbuf
  157.     mov    ah,conout        ; console output function
  158. proc2:    lodsb
  159.     mov    dl,al
  160.     int    dos
  161.     loop    proc2            ; print all digits
  162.     popf
  163.     pop    di
  164.     pop    si
  165.     ret
  166. proct    endp
  167.  
  168. ;    This is the CONNECT command.
  169.  
  170. TELNET     PROC    NEAR
  171.     mov ah,cmcfm
  172.     call comnd        ; Get a confirm.
  173.      jmp r            ;  Didn't get a confirm.
  174.     mov ah,prstr        ; Output
  175.     mov dx,offset crlf    ; a crlf.
  176.     int dos
  177.     call domsg        ; Reassure user. [19b]
  178.     mov al,0        ; initial flags
  179.     cmp flags.modflg,0    ; mode line on?
  180.     jne tel010        ; yes, go on
  181.     or al,modoff        ; no, make sure it stays off
  182.  
  183. tel010:    or al,havtt        ; defaults (!)
  184.     cmp flags.debug,0    ; debug mode?
  185.     jz tel0            ; no, keep going
  186.     or al,trnctl        ; yes, show control chars
  187. tel0:    cmp flags.wrpflg,0    ; wrap mode?
  188.     jz tel011        ; no, keep going
  189.     or al,lnwrap
  190. tel011:    cmp flags.vtflg,0    ; vt52 emulation?
  191.     jz tel1
  192.     or al,emheath
  193. tel1:    mov bx,portval
  194.     cmp [bx].ecoflg,0    ; echoing?
  195.     jz tel2
  196.     or al,lclecho
  197. tel2:    mov targ.flgs,al    ; store flags
  198.     mov ah,flags.comflg
  199.     mov targ.prt,ah        ; Port 1 or 2
  200.     mov ah,trans.escchr
  201.     mov targ.escc,ah
  202.     mov ah,[bx].parflg
  203.     mov targ.parity,ah
  204.     mov ax,[bx].baud
  205.     mov targ.baudb,al
  206.     mov ah,flags.capflg
  207.     and ah,capt
  208.     or targ.flgs,ah
  209.     call serini        ; init serial port
  210. tem:    mov ax,offset targ    ; Point to terminal arguments
  211.     call term
  212.     or targ.flgs,scrsam    ; assume screen is the same.
  213.     mov flags.modflg,1    ; assume mode line is on
  214.     test targ.flgs,modoff    ; did someone turn it off?
  215.     jz tem1            ; no, go on
  216.     mov flags.modflg,0    ; yes, remember it's off
  217. tem1:    mov flags.wrpflg,0    ; assume not wrap mode
  218.     test targ.flgs,lnwrap    ; in wrap mode?
  219.     jz tem2            ; no, continue
  220.     mov flags.wrpflg,1
  221. tem2:
  222. intchr:    mov ah,dconio        ; Direct console I/O.
  223.     mov dl,0FFH        ; Input.
  224.     int dos            ; Get a char.
  225.     jz intchr        ; no char, keep looking
  226.     mov ah,al
  227.     jz intchr        ; If so, go until we get a char.
  228.     cmp ah,' '        ; space - ignore it
  229.     je tem
  230.     mov bh,ah        ; Save the actual char.
  231.     and ah,not ('a'-'A')    ; Convert to upper case.
  232.     or ah,40H        ; convert ctl-char to actual char.
  233.     cmp ah,'C'        ; Is it close?
  234.     jne intch1
  235.     call serrst        ; reset serial port
  236.     jmp rskp        ; and return
  237. intch1: cmp ah,'S'        ; Is it status?
  238.     jnz intch2
  239.     call stat0        ; If so, call stat0.
  240.     call puthlp        ; put help on screen
  241.     mov dx,offset sttmsg
  242.     mov ah,prstr
  243.     int dos
  244. intch1a:mov ah,coninq        ; console input, no echo
  245.     int dos
  246.     cmp al,' '        ; space?
  247.     jne intch1a
  248.     and targ.flgs,not scrsam ; remember screen changed.
  249.     jmp tem
  250. intch2: cmp ah,'B'        ; Send a break? [20g]
  251.     jne intch3        ; No. [20g]
  252.     call sendbr        ; Yes, so send a break. [20g]
  253.     jmp tem            ; And return.  [20g]
  254. intch3:    cmp ah,'M'        ; mode line?
  255.     jne intch4
  256.     xor targ.flgs,modoff    ; toggle mode line
  257.     xor flags.modflg,1    ; toggle this one as well
  258.     jmp tem            ; and reconnect
  259. intch4:    cmp bh,'?'        ; Is it help?
  260.     jne intch5        ; If not, go to the next check.
  261.     mov ax,offset inthlp    ; If so, get the address of the help message.
  262.     call puthlp        ; write help msg
  263.     mov dx,offset intprm
  264.     mov ah,prstr        ; Print it.
  265.     int dos
  266.     and targ.flgs,not scrsam ; remember screen changed
  267.     jmp intchr        ; Get another char.
  268. intch5: cmp bh,trans.escchr    ; Is it the escape char?
  269.     jne intch7        ; If not, go send a beep to the user.
  270. intch6: mov ah,al
  271.     call outchr
  272.     nop
  273.     nop
  274.     nop
  275.     jmp tem            ; Return, we are done here.
  276. intch7:    cmp ah,'Q'        ; maybe want to stop logging?
  277.     jne intch8
  278.     test targ.flgs,capt    ; not capturing, can't do this
  279.     jz intc11
  280.     and targ.flgs,not capt ; stop capturing
  281.     jmp tem            ; and resume
  282. intch8:    cmp ah,'R'        ; maybe resume?
  283.     jne intch9        ; no, keep going
  284.     cmp flags.capflg,0    ; can we capture?
  285.     jz intc11        ; no, forget it
  286.     test targ.flgs,capt    ; already capturing?
  287.     jnz intc11        ; yes, can't toggle back on then
  288.     or targ.flgs,capt    ; else turn flag on
  289.     jmp tem            ; and resume
  290. intch9:    cmp bh,'0'        ; perhaps want a null (note original chr in bh)
  291.     jne intc10
  292.     mov ah,0
  293.     call outchr
  294.     nop
  295.     nop
  296.     nop
  297.     jmp tem
  298. intc10:    cmp ah,'P'        ; maybe want to push?
  299.     jne intc11        ; no, go on
  300.     call fpush        ; try pushing
  301.      nop
  302.      nop
  303.      nop            ; isn't this silly?
  304.     mov dx,offset sttmsg
  305.     mov ah,prstr
  306.     int dos
  307.     jmp intch1a        ; wait for space
  308. intc11:    call beep
  309.     jmp tem
  310. TELNET  ENDP
  311.  
  312. ; Reassure user about connection to the host.  Tell him what escape
  313. ; sequence to use to return and the communications port and baud
  314. ; rate being used.   [19b] 
  315.  
  316. DOMSG    PROC    NEAR
  317.     mov ah,prstr
  318.     mov dx,offset tmsg1
  319.     int dos
  320.     call escprt
  321.     mov ah,prstr
  322.     mov dx,offset tmsg3
  323.     int dos
  324.     ret
  325. DOMSG    ENDP
  326.  
  327.  
  328. ; Set parity for character in Register AL.
  329.  
  330. dopar:    push bx
  331.     mov bx,portval
  332.     cmp [bx].parflg,parnon    ; No parity?            [10 start]
  333.     je parret        ; Just return
  334.     cmp [bx].parflg,parevn    ; Even parity?
  335.     jne dopar0
  336.     and al,07FH        ; Strip parity.
  337.     jpe parret        ; Already even, leave it.
  338.     or al,080H        ; Make it even parity.
  339.     jmp parret
  340. dopar0:    cmp [bx].parflg,parmrk    ; Mark parity?
  341.     jne dopar1
  342.     or al,080H        ; Turn on the parity bit.
  343.     jmp parret
  344. dopar1:    cmp [bx].parflg,parodd    ; Odd parity?    
  345.     jne dopar2
  346.     and al,07FH        ; Strip parity.
  347.     jpo parret        ; Already odd, leave it.
  348.     or al,080H        ; Make it odd parity.
  349.     jmp parret
  350. dopar2: and al,07FH        ; Space parity - turn off parity bit.
  351. parret:    pop bx
  352.     ret                    ; [10 end]
  353.  
  354. inicpt    proc    near
  355.     mov    capbp,offset capbuf
  356.     mov    caplft,128        ; init buffer ptr & chrs left
  357.     ret                ; and return
  358. inicpt    endp
  359.  
  360.  
  361. cptchr    proc    near            ; capture routine, char in al
  362.     push    di
  363.     mov    di,capbp
  364.     mov    byte ptr [di],al
  365.     inc    di
  366.     mov    capbp,di        ; restore pointer
  367.     pop    di
  368.     dec    caplft            ; decrement chars remaining
  369.     jnz    cptch1            ; more room, forget this part
  370.     call    cptdmp            ; dump the info
  371.     call    inicpt            ; re-init ptrs.
  372. cptch1:    ret                ; and return
  373. cptchr    endp
  374.  
  375. cptdmp    proc    near            ; empty the capture buffer
  376.     push    ax
  377.     push    dx
  378.     mov    ah,setdma
  379.     mov    dx,offset capbuf    ; the capture routine buffer
  380.     int    dos
  381.     mov    ah,writef
  382.     mov    dx,offset cptfcb
  383.     int    dos            ; write out the block
  384. ;*** must be fixed... check error returns, disable capturing,
  385. ;*** figure out how to put dma address back
  386.     mov    dx,offset buff
  387.     mov    ah,setdma
  388.     int    dos            ; put dma back
  389.     pop    dx
  390.     pop    ax
  391.     ret
  392. cptdmp    endp
  393.  
  394. clscpt    proc    near
  395.     test    flags.capflg,0FFH    ; doing capture
  396.     jnz    clscp1            ; yes, go ahead
  397.     mov    dx,offset erms22
  398.     mov    ah,prstr
  399.     int    dos
  400.     jmp    rskp
  401. clscp1:    mov    ah,cmcfm
  402.     call    comnd
  403.      jmp    r
  404. clscpi:    mov    al,'Z'-64        ; control-z for eof...
  405.     call    cptchr            ; output to file
  406.     mov    al,caplft
  407.     cmp    al,128            ; is buffer empty?
  408.     je    clscp2            ; yes, forget this stuff
  409.     call    cptdmp            ; dump buffer (preserves registers)
  410. clscp2:    mov    ah,0
  411.     sub    word ptr cptfcb+16,ax    ; subtract remaining from low filsize
  412.     sbb    word ptr cptfcb+18,0    ; and from high size (with borrow)
  413.     mov    ah,closf
  414.     mov    dx,offset cptfcb
  415.     int    dos            ; close up file
  416.     mov    flags.capflg,0        ; no longer capturing...
  417.     jmp    rskp            ; and return
  418. clscpt    endp
  419.  
  420. ; enter with ax/scan code to define, si/ pointer to definition, cx/ length
  421. ; of definition.  Defines it in definition table.
  422. defkey    proc    near
  423.     cmp    deflen,cx
  424.     jg    defk0        ; room in buffer, continue
  425.     mov    dx,offset erms2
  426.     call    tmsg
  427.     ret
  428. defk0:    push    ax        ; save scan code
  429.     mov    ax,ds
  430.     mov    es,ax        ; address data segment
  431.     mov    di,defptr    ; this is where the def gets built
  432.     inc    di        ; leave a byte for length
  433. defk1:    lodsb            ; get a byte from the source
  434.     cmp    al,'\'        ; escape?
  435.     jne    defk2        ; no, just deposit him
  436.     dec    cx        ; count available is one less
  437.     call    trnesc        ; translate the escape sequence
  438.     inc    cx        ; account for '\' (loop will decrement again).
  439. defk2:    stosb            ; drop off character
  440.     loop    defk1        ; and keep going while we have more
  441.     mov    ax,di        ; get ptr to end
  442.     dec    ax        ; back up pointer to end
  443.     mov    si,defptr    ; pick up old ptr value
  444.     sub    ax,si        ; this is actual length used
  445.     sub    deflen,ax    ; account for the space
  446.     mov    byte ptr [si],al ; fill in length of entry
  447.     mov    defptr,di    ; this is next free byte
  448. ; definition address is in si
  449.     pop    ax        ; recover scan code
  450.     mov    cx,targ.klen    ; length of scan table
  451.     jcxz    defk4        ; not there, just go add it
  452.     mov    di,offset scntab ; the scan code table
  453.     repne    scasw        ; look for this one
  454.     jne    defk4        ; not defined already
  455.     sub    di,offset scntab + 2 ; compute index into table
  456.     mov    deftab[di],si    ; fill in address
  457.     ret            ; and return
  458. defk4:    mov    di,targ.klen    ; get length again
  459.     inc    di
  460.     cmp    di,scntlen
  461.     ja    defk5        ;** ignore def if over size
  462.     mov    targ.klen,di    ; update length
  463.     shl    di,1        ; double for word index
  464.     mov    scntab[di-2],ax    ; put scan code into table
  465.     mov    deftab[di-2],si    ; and fill in definition
  466.     ret            ; that's it
  467. defk5:    mov    dx,offset erms3
  468.     call    tmsg
  469.     ret
  470. defkey    endp
  471.  
  472. ; enter with si/ source pointer, cx/ count
  473. ; converts an escape sequence, updates all pointers
  474. trnesc    proc    near
  475.     push    bx
  476.     push    dx        ; preserve these
  477.     mov    al,0        ; this is current accumulation
  478.     jcxz    trnes2        ; empty string, forget it
  479.     mov    bl,3        ; this is max # of digits to use
  480.     mov    bh,8        ; this is radix
  481. trnes1:    mov    dl,[si]
  482.     cmp    dl,'0'
  483.     jb    trnes2        ; out of range, stop here
  484.     cmp    dl,'7'
  485.     ja    trnes2
  486.     inc    si        ; accept character
  487.     sub    dl,'0'        ; convert to binary
  488.     mul    bh        ; shift accumulation
  489.     add    al,dl        ; add to accumulation
  490.     dec    bl        ; decrement digit counter
  491.     loopnz    trnes1        ; and keep trying
  492. trnes2:    pop    dx
  493.     pop    bx
  494.     ret            ; and return
  495. trnesc    endp
  496.  
  497. ; clear all def's
  498. clrdef    proc    near
  499.     mov    targ.klen,0    ; no defn's
  500.     mov    defptr,offset defbuf ; pointer starts at beginning
  501.     mov    deflen,defbsiz    ; amt of space left in buffer
  502.     ret
  503. clrdef    endp
  504.  
  505. ; print a $-message in dx
  506. tmsg    proc    near
  507.     mov    ah,prstr
  508.     int    dos
  509.     ret
  510. tmsg    endp
  511.  
  512. ; Jumping to this location is like retskp.  It assumes the instruction
  513. ;   after the call is a jmp addr.
  514.  
  515. RSKP    PROC    NEAR
  516.     pop bp
  517.     add bp,3
  518.     push bp
  519.     ret
  520. RSKP    ENDP
  521.  
  522. ; Jumping here is the same as a ret.
  523.  
  524. R    PROC    NEAR
  525.     ret
  526. R    ENDP
  527.  
  528. code    ends 
  529.     end
  530.  
  531.